home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 20
/
Cream of the Crop 20 (Terry Blount) (1996).iso
/
program
/
cluster2.zip
/
CLUSTER2.BAS
next >
Wrap
BASIC Source File
|
1996-07-04
|
23KB
|
609 lines
$COMPILE EXE "CLUSTER2.EXE"
'+---------------------------------------------------------------------------+
'| Clusters.bas -- predicts/reports cluster usages & disk space wasted |
'| based on the cluster sizes used by various operating |
'| systems and how much space is currently in use |
'|---------------------------------------------------------------------------|
'|Revision History |
'|---------------------------------------------------------------------------|
'|When What |
'| 5 Nov 95 Initial coding and release |
'|19 Nov 95 Fixed problem with counting one too many clusters for |
'| each file. Also fixed the problem with a divide by zero error |
'| if a drive had only directories (no files) in the root. |
'| |
'| Added: |
'| - the ability to do 512byte clusters (HPFS and NTFS) |
'| - Capability to process one drive without zeroing the totals |
'| |
'|14 Jun 96 Started Code for version 2.0 |
'| - More detailed reporting |
'| - just for the fun of it |
'| - cleaner interface |
'| - uses modified windowing routines |
'| |
'+---------------------------------------------------------------------------+
$STACK 32766
$OPTION CNTLBREAK ON
$LIB IPRINT ON
defint a-z
%False = 0
%True = NOT(%False)
%FLAGS = 0 ' constants for CPU registers -- we will be
%AX = 1 ' calling some DOS routines later
%BX = 2
%CX = 3
%DX = 4
%SI = 5
%DI = 6
%BP = 7
%DS = 8
%ES = 9
$INCLUDE "..\lib\PB3BOXES.INC"
%ClustSizes = 6
TYPE DTAData ' all the information we want about a file
Reserved AS STRING * 21 ' is in this data structure in DOS memory
Attr AS BYTE
FileTime AS WORD
FileDate AS WORD
Size AS DWORD
TheName AS STRING * 13
TheRest AS STRING * 21
END TYPE
TYPE DirDataType
DirName AS STRING * 35
FileCount AS LONG
BytesAlloc AS QUAD
BytesUsed AS QUAD
END TYPE
SHARED Box1Color%, Box1High%, Box2Color%, Box2High%, Box3Color%, Box3High%
SHARED DirCount%, TempFile$, TempFileNum%, DirNames$(), ReportData&()
SHARED DrvCluster&
DIM DirNames$(0:6000)
DIM DirData AS SHARED DirDataType
DIM ReportData&(1:%ClustSizes,1:5)
'
' Each primary record in the ReportData& array has 5 elements:
' ReportData&(x%,1) = Cluster Size
' ReportData&(x%,2) = Total Clusters Allocated
' ReportData&(x%,3) = Total Bytes Allocated
' ReportData&(x%,4) = Total Bytes Used
' ReportData&(x%,5) = Total Bytes Wasted
'
ReportData&(1,1) = 512 ' initialize the records with default sizes
ReportData&(2,1) = 2048
ReportData&(3,1) = 4096
ReportData&(4,1) = 8192
ReportData&(5,1) = 16384
ReportData&(6,1) = 32768
MainBack% = MakeAttr%(%White,%Black)
IF pbvScrnMode = 7 THEN ' Monochrome Monitor
MainHigh% = MakeAttr%(%BrightWhite, %Blue)
Box1Color% = MakeAttr%(%Black,%White)
Box1High% = MakeAttr%(%BrightWhite,%White)
Box1High2% = MakeAttr%(%BrightWhite,%White)
Box2Color% = MakeAttr%(%White,%Black)
Box2High% = MakeAttr%(%BrightWhite,%Black)
Box2High2% = MakeAttr%(%BrightWhite,%Black)
Box3Color% = MakeAttr%(%Black,%White)
Box3High% = MakeAttr%(%White,%Black)
Box3High2% = MakeAttr%(%White,%Black)
ELSE
MainHigh% = makeAttr%(%BrightWhite,%Blue)
Box1Color% = MakeAttr%(%BrightWhite,%Blue)
Box1High% = MakeAttr%(%Yellow,%Blue)
Box1High2% = MakeAttr%(%BrightCyan,%Blue)
Box2Color% = MakeAttr%(%Black,%Cyan)
Box2High% = MakeAttr%(%Blue,%Cyan)
Box2High2% = MakeAttr%(%Yellow,%Cyan)
Box3Color% = MakeAttr%(%Black,%Green)
Box3High% = MakeAttr%(%BrightWhite,%Green)
Box3High2% = MakeAttr%(%Yellow,%Green)
END IF
'
' Here, we save the current screen, draw our own, then get started
'
CALL BoxInit(5)
SaveCsrX% = POS(d%)
SaveCsrY% = CSRLIN
CALL MakeBox(1,1,25,80,MainBack%,0)
CALL QFILL(2,1,24,80,177,MainBack%)
CALL QFILL(1,1,1,80,32,MainHigh%)
CALL PrtBox(1,1,"Clusters V2.0 (c)1995-96",MainHigh%)
CALL PrtBox(1,46,"Bud Durland - bdurland@northnet.org",MainHigh%)
CALL Greeting
BeginAgain:
'
' Get the drive/directory to process
'
VIEW TEXT (1,1)-(80,25)
IF LEN(StartDir$) = 0 THEN StartDir$ = LEFT$(CURDIR$,2)
CALL MakeBox(5,20,8,40,Box2Color%,1)
CALL PrtBox(1,0,"Enter Drive or Directory to process",-1)
CALL LineEdit(8,30,StartDir$,Box2High%,"",CHR$(13,27),ExitKey%,20,50)
CALL RemoveBox
IF ExitKey% = 27 THEN GOTO WrapUp
'
' Fixup the user's input, then load the directory names
'
IF LEN(StartDir$) = 0 THEN StartDir$ = LEFT$(CURDIR$,2)
IF INSTR(StartDir$,":") = 0 THEN StartDir$ = LEFT$(CURDIR$,2)
StartDir$ = UCASE$(RTRIM$(StartDir$, ANY " \/")) + "\"
CALL GetDriveInfo(StartDir$, DrvCluster&, DrvClustCnt&)
CALL LoadDirNames(StartDir$)
'
' Create a screen for displaying the stats
'
CALL MakeBox(3,4,23,74,Box2Color%,1)
a$ = "Scanning Drive " + LEFT$(DirNames$(0),2) + " Curren Cluster Size " + STR$(DrvCluster&)
CALL PrtBox(1,1,a$,-1)
CALL PrtBox(4,1,"Clust Clust Kbyte KByte KByte %Slack",Box2High%)
CALL PrtBox(5,1,"Size Alloc Alloc Used Wasted space",Box2High%)
CALL PrtBox(6,1,"═══════════════════════════════════════════════════════════════════════",Box2High%)
CALL PrtBox(14,0,"HPFS & NTFS (any size) = 512 byte Clusters",-1)
CALL PrtBox(15,0,"FAT/VFAT 0MB - 128MB = 2048 byte Clusters",-1)
CALL PrtBox(16,0,"FAT/VFAT 129MB - 256MB = 4096 byte Clusters",-1)
CALL PrtBox(17,0,"FAT/VFAT 257MB - 512MB = 8192 byte Clusters",-1)
CALL PrtBox(18,0,"FAT/VFAT 513MB - 1.02GB = 16284 byte Clusters",-1)
CALL PrtBox(19,0,"FAT/VFAT 1.02GB - 2.04GB = 32768 byte Clusters",-1)
'
' Now go through each directory, getting information on each file
' it contains. Display the data; and accumulate information about
' each directory for storage in a temporary file
'
TempFileNum% = AllocTempFile% ' func returns handle of a temp file
IF TempFileNum% = 0 THEN
a$ = "Failed to allocate a temporary file" + CHR$(10) + _
"Clusters cannot continue"
CALL MsgBox(a$,"",MainHigh%)
CALL RemoveBox
END
END IF
FOR DirPtr% = 0 TO DirCount%
TheDir$ = DirNames$(DirPtr%)
DirFileCnt& = 0
CALL PrtBox(2,1,"Dir: ",-1) ' keep the user entertained
j$ = TheDir$
IF LEN(TheDir$) > 65 THEN
j$ = LEFT$(TheDir$,30) + "...." + RIGHT$(TheDir$,30)
END IF
CALL PrtEOL(2,6,TheDir$,Box2High2%)
TheFile$ = DIR$(TheDir$+"*.*",55) ' use attr of 55 to get all files
WHILE LEN(TheFile$) > 0
INCR FileCnt&,1
INCR DirFileCnt&,1
z? = ATTRIB(TheDir$ + TheFile$)
IF (TheFile$ = ".") OR (TheFile$ = "..") OR _ ' the entries "." and ".."
(BIT(z?,4)) THEN ' are special, and don't
TheFile$ = DIR$ ' count here, bit 4 set
DECR DirFileCnt& ' means this file is a
ITERATE ' dir; don't count it
END IF
fSize& = GetFileSize&(TheDir$ + TheFile$)
FOR x% = 1 TO %ClustSizes ' Compute file stats
Cluster& = ReportData&(x%,1)
TotalFSize&& = TotalFSize&& + k&
ClustAloc& = (fSize& \ Cluster&) ' get number of whole clust
f& = fSize& MOD Cluster& ' adju